package com.bw.counter.net

import androidx.lifecycle.MutableLiveData
import com.blankj.utilcode.util.ApiUtils.Api
import com.bw.common.vm.BaseViewModel
import com.bw.counter.entity.ChargeData
import com.bw.counter.entity.CounterData
import com.bw.http.utils.zgr.OkHttpClientManager

class CounterViewModel:BaseViewModel() {
    val api :ApiService = OkHttpClientManager.retrofitInstance.create(ApiService::class.java)
    val getCounterSuccess by lazy { MutableLiveData<List<CounterData>>() }
    fun getCount(payId:Int){
        executeNetwork(
            {api.getCount(payId)},
            getCounterSuccess::postValue
        )
    }
    val getDetailSuccess by lazy { MutableLiveData<List<CounterData>>() }
    fun getDetail(id:Int){
        executeNetwork(
            {api.getDetail(id)},
            getDetailSuccess::postValue
        )
    }
    val deleSuccess by lazy { MutableLiveData<Boolean>() }
    fun delItem(id:Int){
        executeNetwork(
            {api.delCount(id)},
            deleSuccess::postValue
        )
    }

    val addCountSuccess by lazy { MutableLiveData<CounterData>() }
    fun addCount(counterData: CounterData){
        executeNetwork(
            {api.addCounter(counterData)},
            addCountSuccess::postValue
        )
    }
    val chargeSuccess by lazy { MutableLiveData<List<ChargeData>>() }
    fun getCharge(id:Int){
        executeNetwork(
            {api.getCharge(id)},
            chargeSuccess::postValue
        )
    }
}